class Solution {
    public long maximumSubsequenceCount(String text, String pattern) {
        long ret = 0;
        int cnt1 = 0, cnt2 = 0;
        for (int i = 0; i < text.length(); i++) {
            if (text.charAt(i) == pattern.charAt(1)) {
                ret += cnt1;
                cnt2++;
            }
            if (text.charAt(i) == pattern.charAt(0)) {
                cnt1++;
            }
        }
        return ret + Math.max(cnt1, cnt2);
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.maximumSubsequenceCount("abdcdbc", "ac"));
    }
}